home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / grafik / raytracing / rayshade-4.0.6.3 / libray / libtext / sky.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  1.8 KB  |  81 lines

  1. /*
  2.  * sky.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * sky.c,v 4.1 1994/08/09 08:03:15 explorer Exp
  17.  *
  18.  * sky.c,v
  19.  * Revision 4.1  1994/08/09  08:03:15  explorer
  20.  * Bump version to 4.1
  21.  *
  22.  * Revision 1.1.1.1  1994/08/08  04:52:15  explorer
  23.  * Initial import.  This is a prerelease of 4.0.6enh3, or 4.1 possibly.
  24.  *
  25.  * Revision 4.0  91/07/17  14:43:43  kolb
  26.  * Initial version.
  27.  * 
  28.  */
  29. #include "texture.h"
  30. #include "sky.h"
  31.  
  32. Sky *
  33. SkyCreate(scale, h, lambda, octaves, cthresh, lthresh)
  34. Float h, lambda, scale, cthresh, lthresh;
  35. int octaves;
  36. {
  37.     Sky *sky;
  38.  
  39.     sky = (Sky *)Malloc(sizeof(Sky));
  40.     sky->beta = 1. + 2 * h;
  41.     sky->omega = pow(lambda, -0.5 * sky->beta);
  42.     sky->lambda = lambda;
  43.     sky->scale = scale;
  44.     sky->cthresh = cthresh;
  45.     sky->lthresh = lthresh;
  46.     sky->octaves = octaves;
  47.     return sky;
  48. }
  49.  
  50. void
  51. SkyApply(sky, prim, ray, pos, norm, gnorm, surf)
  52. Sky *sky;
  53. Geom *prim;
  54. Ray *ray;
  55. Vector *pos, *norm, *gnorm;
  56. Surface *surf;
  57. {
  58.     Float It, maxval;
  59.  
  60.     It = fBm(pos, sky->omega, sky->lambda, sky->octaves);
  61.     maxval = 1. / (1. - sky->omega);
  62.     /*
  63.      * Map from [-maxval,maxval] to [0,1]
  64.      */
  65.     It = (maxval +  It) * 0.5/maxval;
  66.  
  67.     It = (It - sky->lthresh) / (sky->cthresh - sky->lthresh);
  68.     if (It < 0.)
  69.         It = 0;
  70.     else if (It > 1.)
  71.         It = 1;
  72.  
  73.     if (sky->scale != 0.)
  74.         It = pow(It, sky->scale);
  75.  
  76.     surf->transp = 1. - It;
  77.  
  78.     ColorScale(It, surf->diff, &surf->diff);
  79.     ColorScale(It, surf->amb, &surf->amb);
  80. }
  81.